package com.ruofeng.app.privilege.resource.menu

import com.mongodb.Mongo
import org.junit.Test
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.script.ExecutableMongoScript
import org.springframework.data.mongodb.core.script.NamedMongoScript


/**
 * Created by 邱鹏 on 2017/7/27.
 */
class IndexControllerTest {
    @Test
    fun getMenuByCode() {
        val mongo = Mongo("localhost", 27017)
        val template = MongoTemplate(mongo, "kotlin")
        val scriptOps = template.scriptOps()
// Execute script directly
        val echoScript = ExecutableMongoScript("function(x) { db.getCollection('echo').save({test:x});return x; }")
        scriptOps.execute(echoScript, "directly execute script")
// Register script and call it later
        scriptOps.register(NamedMongoScript("echo", echoScript))
        var result=scriptOps.call("echo", "execute script via name")
        print(result)
    }

}